package com.playball.lottery.frm.yhzx;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.MyDialog;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.frm.buyhall.CQSSCActivity;
import com.playball.lottery.frm.buyhall.CQSSCListActivity;
import com.playball.lottery.frm.buyhall.DltxhActivity;
import com.playball.lottery.frm.buyhall.DltxhlbActivity;
import com.playball.lottery.frm.buyhall.ElvSelFiveActivity;
import com.playball.lottery.frm.buyhall.ElvSelFiveListActivity;
import com.playball.lottery.frm.buyhall.ElvYunDJActivity;
import com.playball.lottery.frm.buyhall.ElvYunDJListActivity;
import com.playball.lottery.frm.buyhall.Fc3dListActivity;
import com.playball.lottery.frm.buyhall.Fc3dxhActivity;
import com.playball.lottery.frm.buyhall.Kuai3Activity;
import com.playball.lottery.frm.buyhall.Kuai3ListActivity;
import com.playball.lottery.frm.buyhall.N7lxhActivity;
import com.playball.lottery.frm.buyhall.N7lxhlbActivity;
import com.playball.lottery.frm.buyhall.N7xxhActivity;
import com.playball.lottery.frm.buyhall.N7xxhlbActivity;
import com.playball.lottery.frm.buyhall.Pailie3ListActivity;
import com.playball.lottery.frm.buyhall.Pailie3xhActivity;
import com.playball.lottery.frm.buyhall.Pailie5ListActivity;
import com.playball.lottery.frm.buyhall.Pailie5xhActivity;
import com.playball.lottery.frm.buyhall.SsqxhActivity;
import com.playball.lottery.frm.buyhall.SsqxhlbActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.LotUtil;
import com.playball.lottery.util.PreferencesUtils;


/**
 * 追号详情
 * 
 * @author Administrator
 * 
 */
public class ZhDetailActivity extends ListActivity {

	private List<Map<String, Object>> mData;
	private Map<String, Object> rData;
	private TextView textTitle;
	private TextView textLotNum;
	// private TextView textBuyed;
	private TextView textStatus;
	private TextView btnStop;
	TextView tvMoney;
	TextView tv_allbuy_num;
	TextView tv_finishbuy_num;
	TextView tv_zh_time;
	ImageView iv_lot_icon;

	private String msg; // 停止追号返回的Message
	private String chaseID;
	String allMoney;
	private String DataSourceID = "1";
	/** 终止条件 */
	private TextView textStopCondition;
	private View view;
	private String chaseDetailID = null;
	private Button btn_go_buy;
	private Intent it;
	private PreferencesUtils pUtil;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.yhzx_zhdetail);
		pUtil = new PreferencesUtils(this, Constants.PREFERENCES_NAME);
		titleBar();

		initView();

		Intent intent = getIntent();
		chaseID = intent.getStringExtra("ChaseID");
		allMoney = intent.getStringExtra("AllMoney");
		AsyncLoader task = new AsyncLoader();
		String[] dyn = new String[2];
		JSONObject paramArr = new JSONObject();
		try {
			// 设置请求所需参数
			paramArr.put("ChaseID", chaseID);
			paramArr.put("DataSource", DataSourceID);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
		dyn[0] = paramArr.toString();
		// 追号详情
		dyn[1] = "113";// 118
		task.execute(dyn);

		// 停止追号
		btnStop.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				MyDialog.Builder dialog = new MyDialog.Builder(
						ZhDetailActivity.this);
				dialog.setTitle("停止追号提示");
				dialog.setMessage("确定要终止追号任务吗?");
				dialog.setPositiveButton("确定",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								startStopZhThread();
								dialog.cancel();
							}
						});
				dialog.setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								dialog.cancel();
							}
						}).create().show();

			}
		});
	}

	public void onResume() {
		super.onResume();
		
		if (getListAdapter() != null) {
			((MyAdapter) getListAdapter()).notifyDataSetChanged();
		}
	}

	public void onPause() {
		super.onPause();
		
	}

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		ShowTipDialog showdialog = new ShowTipDialog();

		String action;

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(ZhDetailActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;

			action = paramsArr[1];
			// 获取请求返回值
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0],
					UserID, action, getApplicationContext());
			// 获取请求返回值
			System.err.println(strResult);
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (action.equals("113")) {
							mData = getData(result);
							MyAdapter adapter = new MyAdapter(mData);
							setListAdapter(adapter);
							setTextView();
						}
						if (action.equals("114")) {
							msg = stopZh(result);
							Toast.makeText(ZhDetailActivity.this, msg,
									Toast.LENGTH_LONG).show();
							if (TextUtils.equals(stopZhCode(result), "0")) {// 停止追号成功
																			// 刷新当前页面
								AsyncLoader task = new AsyncLoader();
								String[] dyn = new String[2];
								JSONObject paramArr = new JSONObject();
								try {
									// 设置请求所需参数
									paramArr.put("ChaseID", chaseID);
									paramArr.put("DataSource", DataSourceID);
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									// e.printStackTrace();
								}
								dyn[0] = paramArr.toString();
								// 追号详情
								dyn[1] = "113";// 118
								task.execute(dyn);
							}
						}
						// 撤销单期
						if (action.equals("1141")) {
							msg = stopZh(result);
							Toast.makeText(ZhDetailActivity.this, msg,
									Toast.LENGTH_LONG).show();
							if (TextUtils.equals(stopZhCode(result), "0")) {// 停止追号成功
								// 刷新当前页面
								AsyncLoader task = new AsyncLoader();
								String[] dyn = new String[2];
								JSONObject paramArr = new JSONObject();
								try {
									// 设置请求所需参数
									paramArr.put("ChaseID", chaseID);
									paramArr.put("DataSource", DataSourceID);
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									// e.printStackTrace();
								}
								dyn[0] = paramArr.toString();
								// 追号详情
								dyn[1] = "113";// 118
								task.execute(dyn);
							}
						}
						showdialog.closeDialog();
					} else {
						Toast.makeText(ZhDetailActivity.this,
								js.getString("Data"), Toast.LENGTH_SHORT)
								.show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					showdialog.closeDialog();
				}
			} else {
				Toast.makeText(ZhDetailActivity.this,
						getString(R.string.problem_01), Toast.LENGTH_LONG)
						.show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	public class MyAdapter extends BaseAdapter {

		private List<Map<String, Object>> myData;

		public MyAdapter(List<Map<String, Object>> data) {
			this.myData = data;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return myData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return myData.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@SuppressLint("ResourceAsColor")
		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// TODO Auto-generated method stub
			if (convertView == null) {
				convertView = getLayoutInflater().inflate(
						R.layout.yhzx_zhdetail_list, null);
			}
			new SimpleAdapter(ZhDetailActivity.this, mData,
					R.layout.yhzx_zhdetail_list, new String[] { "Issue",
							"Count", "Multiple", "State" }, new int[] {
							R.id.yhzx_zhdetail_issue, R.id.yhzx_zhdetail_count,
							R.id.yhzx_zhdetail_multiple,
							R.id.yhzx_zhdetail_status });
			// 注数
			TextView tCount = (TextView) convertView
					.findViewById(R.id.yhzx_zhdetail_count);
			tCount.setText(myData.get(position).get("Count").toString());

			// 期号
			TextView tvIssue = (TextView) convertView
					.findViewById(R.id.yhzx_zhdetail_issue);
			tvIssue.setText(myData.get(position).get("Issue").toString());

			// 倍数
			TextView tvMoney = (TextView) convertView
					.findViewById(R.id.yhzx_zhdetail_multiple);
			tvMoney.setText(myData.get(position).get("Multiple").toString());

			// 状态
			TextView tvState = (TextView) convertView
					.findViewById(R.id.yhzx_zhdetail_status);
			tvState.setText(myData.get(position).get("State").toString());

//			final TextView img = (TextView) convertView
//					.findViewById(R.id.yhzx_zhdetail_img);
//			img.setVisibility(View.VISIBLE);
//			if (tvState.getText().toString().equals("已成功")) {
//				img.setText(Html.fromHtml("<u>查看详情</u>"));
//				img.setTextColor(getResources().getColor(
//						R.color.ui_new_btn_yes_normal_solid));
//			} else if (tvState.getText().toString().equals("进行中")) {
//				img.setText(Html.fromHtml("<u>撤销此期</u>"));
//				img.setTextColor(getResources().getColor(
//						R.color.ui_new_btn_no_normal_solid));
//			} else {
//				img.setVisibility(View.INVISIBLE);
//			}
//
//			img.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
//					String schemeID = null;
//					if (mData.get(position).get("SchemeID") != null) {
//						schemeID = mData.get(position).get("SchemeID")
//								.toString();
//					}
//					if (mData.get(position).get("detailID")!=null) {
//						chaseDetailID = mData.get(position).get("detailID").toString();
//					}
//					if (schemeID == null || schemeID.equals("0")) {
//						// 执行单期停止
//						MyDialog.Builder dialog = new MyDialog.Builder(
//								ZhDetailActivity.this);
//						dialog.setTitle("撤销提示");
//						dialog.setMessage("是否确定撤销此期?");
//						dialog.setPositiveButton("确定",
//								new DialogInterface.OnClickListener() {
//									@Override
//									public void onClick(DialogInterface dialog,
//											int which) {
//										stopZhOneThread();
//										dialog.cancel();
//									}
//								});
//						dialog.setNegativeButton("取消",
//								new DialogInterface.OnClickListener() {
//									@Override
//									public void onClick(DialogInterface dialog,
//											int which) {
//										dialog.cancel();
//									}
//								}).create().show();
//						
//						
//						
//					} else {
//						Intent intent = new Intent(ZhDetailActivity.this,
//								PlanDetailsActivity.class);
//						intent.putExtra("SchemeID", schemeID);
//						intent.putExtra("LotName", rData.get("LotName")
//								.toString());
//						intent.putExtra("DataSource", DataSourceID);
//						startActivity(intent);
//					}
//				}
//			});
			return convertView;
		}

	}

	public void initView() {
		textTitle = (TextView) findViewById(R.id.yhzx_zhdetail_title);
		textLotNum = (TextView) findViewById(R.id.yhzx_zhdetail_lotnumber);
		// textBuyed = (TextView) findViewById(R.id.yhzx_zhdetail_buyed);
		// 终止条件
		textStopCondition = (TextView) findViewById(R.id.yhzx_zhdetail_stopcondition);
		textStatus = (TextView) findViewById(R.id.yhzx_zhdetail_status);

		tvMoney = (TextView) findViewById(R.id.yhzx_zhrecord_amount);
		iv_lot_icon = (ImageView) findViewById(R.id.yhzx_lot_icon);
		tv_allbuy_num = (TextView) findViewById(R.id.yhzx_zhrecord_issuenum);
		tv_finishbuy_num = (TextView) findViewById(R.id.yhzx_zhrecord_finish);
		tv_zh_time = (TextView) findViewById(R.id.yhzx_zhrecord_launchtime);

		view = LayoutInflater.from(this).inflate(R.layout.zh_detail_bottom,
				null);
		btnStop = (TextView) view.findViewById(R.id.bottom_right_btn);
		btnStop.setText(Html.fromHtml("<u>停止追号</u>"));
		getListView().addFooterView(view);
		
		btn_go_buy = (Button) findViewById(R.id.btn_go_buy);
	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			int code = Integer.parseInt(js.getString("Code"));
			if (code <= -1) {
				String msg = js.getString("Data");
				Toast.makeText(ZhDetailActivity.this, msg, Toast.LENGTH_LONG)
						.show();
			} else {
				rData = ConvertJsonToList.getMap(js.getString("Data"));
				list = ConvertJsonToList.getList(String
						.valueOf(ConvertJsonToList.getMap(js.getString("Data"))
								.get("item")));
			}
		} catch (JSONException ex) {
			// 异常处理代码
			Log.e("error", ex.toString());
		}

		return list;
	}

	// 对返回数据进行修改
	public List<Map<String, Object>> modifyData(List<Map<String, Object>> data) {
		for (int i = 0; i < data.size(); i++) {
			String issue = data.get(i).get("Issue").toString();
			issue += "期";
			data.get(i).put("Issue", issue);
		}
		return data;
	}

	public void setTextView() {

		String status = rData.get("ChaseState").toString();
		int iNum = Integer.parseInt(rData.get("IssueNum").toString());
		int buyIsNum = Integer.parseInt(rData.get("BuyedIssueNum").toString());

		textTitle.setText(rData.get("LotName").toString()/* + "\t追号记录" */);
//		final int lotid = Integer.parseInt(rData.get("LotID").toString());
//		switch (lotid) {
//		case DefConstants.LOT_ID_QXC://七星彩 3 
//			btn_go_buy.setText("去七星彩投注");
//			break;
//		case DefConstants.LOT_ID_SSQ:
//			btn_go_buy.setText("去双色球投注");
//			break;
//		case DefConstants.LOT_ID_FC3D:
//			btn_go_buy.setText("去福彩3D投注");
//			break;
//		case DefConstants.LOT_ID_QLC:
//			btn_go_buy.setText("去七乐彩投注");
//			break;
//		case DefConstants.LOT_ID_DLT:
//			btn_go_buy.setText("去大乐透投注");
//			break;
//		case DefConstants.LOT_ID_PL3:
//			btn_go_buy.setText("去排列3投注");
//			break;
//		case DefConstants.LOT_ID_PL5:
//			btn_go_buy.setText("去排列5投注");
//			break;
//		case DefConstants.LOT_ID_11X5:
//			btn_go_buy.setText("去11选5投注");
//			break;
//		case DefConstants.LOT_ID_11YDJ:
//			btn_go_buy.setText("去11运夺金投注");
//			break;
//		case DefConstants.LOT_ID_CQSSC:
//			btn_go_buy.setText("去重庆时时彩投注");
//			break;
//		case DefConstants.LOT_ID_KUAI3:
//			btn_go_buy.setText("去快3投注");
//			break;
//		}
//		btn_go_buy.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				it = new Intent();
//				switch (lotid) {
//				case DefConstants.LOT_ID_QXC://七星彩 3 
//					int n7xx_size = pUtil.getInt("n7xx_size", 0);
//					if (n7xx_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < n7xx_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setPl3_ball(pUtil.getString("n7xx_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("n7xx_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("n7xx_play", 0));
//						it.setClass(ZhDetailActivity.this, N7xxhlbActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, N7xxhActivity.class);
//					}
//					break;
//				case DefConstants.LOT_ID_SSQ:
//					int ssq_size = pUtil.getInt("ssq_size", 0);
//					if (ssq_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < ssq_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setSsq_ball(pUtil.getString("ssq_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_ssqdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("ssq_allMoney", 0));
//						it.setClass(ZhDetailActivity.this, SsqxhlbActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, SsqxhActivity.class);
//					}
//					btn_go_buy.setText("去双色球投注");
//					break;
//				case DefConstants.LOT_ID_FC3D:
//					int fc3d_size = pUtil.getInt("fc3d_size", 0);
//					if (fc3d_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < fc3d_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setPl3_ball(pUtil.getString("fc3d_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("fc3d_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("fc3d_play", 0));
//						it.setClass(ZhDetailActivity.this, Fc3dListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, Fc3dxhActivity.class);
//					}
//					btn_go_buy.setText("去福彩3D投注");
//					break;
//				case DefConstants.LOT_ID_QLC:
//					int n7lx_size = pUtil.getInt("n7lx_size", 0);
//					if (n7lx_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < n7lx_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setPl3_ball(pUtil.getString("n7lx_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("n7lx_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("n7lx_play", 0));
//						it.setClass(ZhDetailActivity.this, N7lxhlbActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, N7lxhActivity.class);
//					}
//					btn_go_buy.setText("去七乐彩投注");
//					break;
//				case DefConstants.LOT_ID_DLT:
//					int dlt_size = pUtil.getInt("dlt_size", 0);
//					if (dlt_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < dlt_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setDlt_ball(pUtil.getString("dlt_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_dltdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("dlt_allMoney", 0));
//						it.setClass(ZhDetailActivity.this, DltxhlbActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, DltxhActivity.class);
//					}
//					ApplicationData.getInstance().setIsDLTZhuiJiaClick(false);
//					btn_go_buy.setText("去大乐透投注");
//					break;
//				case DefConstants.LOT_ID_PL3:
//					int pl3_size = pUtil.getInt("pl3_size", 0);
//					if (pl3_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < pl3_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setPl3_ball(pUtil.getString("pl3_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("pl3_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("pl3_play", 0));
//						it.setClass(ZhDetailActivity.this, Pailie3ListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, Pailie3xhActivity.class);
//					}
//					btn_go_buy.setText("去排列3投注");
//					break;
//				case DefConstants.LOT_ID_PL5:
//					int pl5_size = pUtil.getInt("pl5_size", 0);
//					if (pl5_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < pl5_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setPl5_ball(pUtil.getString("pl5_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("pl5_allMoney", 0));
//						it.setClass(ZhDetailActivity.this, Pailie5ListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, Pailie5xhActivity.class);
//					}
//					btn_go_buy.setText("去排列5投注");
//					break;
//				case DefConstants.LOT_ID_11X5:
//					int esf_size = pUtil.getInt("esf_size", 0);
//					if (esf_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < esf_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setElv_ball(pUtil.getString("esf_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("esf_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("esf_play", 0));
//						it.putExtra("prizeIntellChase", pUtil.getInt("esf_prizeIntellChase", 0));
//						it.setClass(ZhDetailActivity.this, ElvSelFiveListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, ElvSelFiveActivity.class);
//					}
//					btn_go_buy.setText("去11选5投注");
//					break;
//				case DefConstants.LOT_ID_11YDJ:
//					int eydu_size = pUtil.getInt("eydu_size", 0);
//					if (eydu_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < eydu_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setElv_ball(pUtil.getString("eydu_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("eydu_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("eydu_play", 0));
//						it.putExtra("prizeIntellChase", pUtil.getInt("eydu_prizeIntellChase", 0));
//						it.setClass(ZhDetailActivity.this, ElvYunDJListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, ElvYunDJActivity.class);
//					}
//					btn_go_buy.setText("去11运夺金投注");
//					break;
//				case DefConstants.LOT_ID_CQSSC:
//					int cqssc_size = pUtil.getInt("cqssc_size", 0);
//					if (cqssc_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < cqssc_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setElv_ball(pUtil.getString("cqssc_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("cqssc_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("cqssc_play", 0));
//						it.putExtra("strPlayType", pUtil.getString("cqssc_type", ""));
//						it.putExtra("prizeIntellChase", pUtil.getInt("cqssc_prizeIntellChase", 0));
//						it.setClass(ZhDetailActivity.this, CQSSCListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, CQSSCActivity.class);
//					}
//					btn_go_buy.setText("去重庆时时彩投注");
//					break;
//				case DefConstants.LOT_ID_KUAI3:
//					int kuai3_size = pUtil.getInt("kuai3_size", 0);
//					if (kuai3_size != 0) {
//						ArrayList<BallDTO> list = new ArrayList<BallDTO>();
//						for (int i = 0; i < kuai3_size; i++) {
//							BallDTO ball = new BallDTO();
//							ball.setElv_ball(pUtil.getString("kuai3_ball" + i, ""));
//							list.add(ball);
//						}
//						it.putExtra("list_elvdto", list);
//						it.putExtra("AllMoney", pUtil.getInt("kuai3_allMoney", 0));
//						it.putExtra("PlayTypeID", pUtil.getInt("kuai3_play", 0));
//						it.putExtra("prizeIntellChase", pUtil.getInt("kuai3_prize", 0));
//						it.setClass(ZhDetailActivity.this, Kuai3ListActivity.class);
//						Toast.makeText(ZhDetailActivity.this, R.string.this_is_the_last_time_you_save_the_number,
//								Toast.LENGTH_SHORT).show();
//					} else {
//						it.setClass(ZhDetailActivity.this, Kuai3Activity.class);
//					}
//					btn_go_buy.setText("去快3投注");
//					break;
//				}
//				startActivity(it);
//				
//			}
//		});
		iv_lot_icon.setImageResource(LotUtil.getLotIconIDByName(rData.get(
				"LotName").toString()));
		// 追号内容
		String lotNum = rData.get("LotNumber").toString();// 直选单式:046&
		if (lotNum.endsWith("&")) {
			lotNum = lotNum.replace("&", " ");
		}
		textLotNum.setText(lotNum);
//		tv_zh_time.setText(rData.get("DateTime").toString());
		// 终止条件
		if (rData.get("StopWhenWinMoney") != null) {
			String strStopWhenWinMoney = rData.get("StopWhenWinMoney")
					.toString();
			// 去掉小数点2.0 变 2
			if (strStopWhenWinMoney.startsWith("0.")) {
				textStopCondition.setText("无");
			} else {
				textStopCondition.setText("单期中奖金额≥"
						+ strStopWhenWinMoney.substring(0,
								strStopWhenWinMoney.indexOf(".")) + "彩豆");
			}
		}
		// textBuyed.setText("共追号" + iNum + "期,已完成" + buyIsNum + "期");
		tv_allbuy_num.setText(iNum + "期");
		tv_finishbuy_num.setText("" + buyIsNum);
		textStatus.setText(status);
		if (status.equals("进行中")) {
			btnStop.setVisibility(View.VISIBLE);
		} else {
			btnStop.setVisibility(View.GONE);
		}
		tvMoney.setText(allMoney);
	}

	private void startStopZhThread() {
		AsyncLoader task = new AsyncLoader();
		String[] dyn = new String[2];
		JSONObject paramArr = new JSONObject();
		try {
			// 设置请求所需参数
			paramArr.put("ChaseID", chaseID);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		dyn[0] = paramArr.toString();
		dyn[1] = "114";
		task.execute(dyn);
	}

	private void stopZhOneThread() {
		AsyncLoader task = new AsyncLoader();
		String[] dyn = new String[2];
		JSONObject paramArr = new JSONObject();
		try {
			// 设置请求所需参数
			paramArr.put("ChaseID", chaseID);
			paramArr.put("ChaseDetailID", chaseDetailID);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}
		dyn[0] = paramArr.toString();
		dyn[1] = "1141";
		task.execute(dyn);
	}

	private String stopZh(String strResult) {
		String msg = null;
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			msg = js.getString("Data");
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}
		return msg;
	}

	private String stopZhCode(String strResult) {
		String msg = null;
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			msg = js.getString("Code");
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}
		return msg;
	}

	public void titleBar() {

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText(R.string.zhrecord_detail);
		TextView title_back = (TextView) findViewById(R.id.top_title_back);
		title_back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
	};

}